import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

public class Reader {

    private BufferedReader bufferedReader;
    private Collection<Player> players;
    private Collection<Coach> coaches;

    public Reader(BufferedReader bufferedReader) {
        this.bufferedReader = bufferedReader;
        this.players = new ArrayList<Player>();
        this.coaches = new ArrayList<Coach>();
    }

    public Collection<Player> getPlayers() {
        return players;
    }

    public Collection<Coach> getCoaches() {
        return coaches;
    }

    public void buildFromFile() throws FileNotFoundException {

        try {
            String personInfo = bufferedReader.readLine();

            while (personInfo!= null) {

                String[] allInfo = personInfo.split(" ");

                if (allInfo[0].equals("Player")){
                    Player newPlayer = new BuildPerson().buildPlayer(personInfo);
                    players.add(newPlayer);
                }
                else if (allInfo[0].equals("Coach")) {
                    Coach newCoach = new BuildPerson().buildCoach(personInfo);
                    coaches.add(newCoach);
                }
                personInfo = bufferedReader.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
